package gdconf

import (
	"server_cluster/common/logger"
)

// 战斗子技能效果配置表

type BattleSubSkillEffectConfig struct {
	EffectId           int32         `csv:"Id" gorm:"primary_key;autoIncrement:false"` // 子技能效果id
	BeginTime          int32         `csv:"Begin_Time,omitempty"`
	EffectType         int32         `csv:"Effect_Type,omitempty"`
	ClientEffectIdList IntArray      `csv:"Show_Effect,omitempty"` // 客户端子技能效果id列表
	Param1             IntArrayArray `csv:"Param1,omitempty"`
	Param2             IntArrayArray `csv:"Param2,omitempty"`
	Param3             int32         `csv:"Param3,omitempty"`
	Param4             int32         `csv:"Param4,omitempty"`
	Param5             int32         `csv:"Param5,omitempty"`
	Param6             IntArray      `csv:"Param6,omitempty"`
}

func (bsse *BattleSubSkillEffectConfig) GetClientEffectIdList() []int32 {
	a := make([]int32, 0)
	for _, v := range bsse.ClientEffectIdList {
		a = append(a, v)
	}
	return a
}

func (bsse *BattleSubSkillEffectConfig) GetParam1() [][]int32 {
	a := make([][]int32, 0)
	for _, v := range bsse.Param1 {
		aa := make([]int32, 0)
		for _, vv := range v {
			aa = append(aa, vv)
		}
		a = append(a, aa)
	}
	return a
}

func (bsse *BattleSubSkillEffectConfig) GetParam2() [][]int32 {
	a := make([][]int32, 0)
	for _, v := range bsse.Param2 {
		aa := make([]int32, 0)
		for _, vv := range v {
			aa = append(aa, vv)
		}
		a = append(a, aa)
	}
	return a
}

func (bsse *BattleSubSkillEffectConfig) GetParam6() []int32 {
	aa := make([]int32, 0)
	for _, vv := range bsse.Param6 {
		aa = append(aa, vv)
	}
	return aa
}

func (bsse *BattleSubSkillEffectConfig) TableName() string {
	return "config_battle_sub_skill_effect_logic"
}

func (g *GameDataConfig) saveBattleSubSkillEffectConfig() {
	saveTableToDb[BattleSubSkillEffectConfig](g.Db, readTable[BattleSubSkillEffectConfig](g.CsvPathPrefix+"BattleSkillEffect.csv"))
}

func (g *GameDataConfig) loadBattleSubSkillEffectConfig() {
	g.GameDataMaps.BattleSubSkillEffectConfigMap = make(map[int32]*BattleSubSkillEffectConfig)
	for _, battleSubSkillEffectConfig := range loadTableFromDb[BattleSubSkillEffectConfig](g.Db) {
		g.GameDataMaps.BattleSubSkillEffectConfigMap[battleSubSkillEffectConfig.EffectId] = battleSubSkillEffectConfig
	}
	logger.Info("BattleSubSkillEffectConfig Count: %v", len(g.GameDataMaps.BattleSubSkillEffectConfigMap))
}

func GetBattleSubSkillEffectConfig(effectId int32) *BattleSubSkillEffectConfig {
	value, exist := CONF.GameDataMaps.BattleSubSkillEffectConfigMap[effectId]
	if !exist {
		logger.Error("[ConfigNotFound] BattleSubSkillEffectConfig, effectId: %v", effectId)
		return nil
	}
	return value
}

func GetBattleSubSkillEffectConfigMap() map[int32]*BattleSubSkillEffectConfig {
	return CONF.GameDataMaps.BattleSubSkillEffectConfigMap
}
